import { createAction } from 'redux-actions';
import * as types from '../constants/ActionTypes.js';
import * as Api from '../utils/WebAPIUtils.js';
import Tool from '../utils/ToolUtils.js';

const getUsers = createAction(types.LOGINERROR, Data => Data);
exports.loginAction = (data, router) => (dispath) =>
  Tool.post(Api.Login.signIn, data, (res) => {
    if (res.code === 200) {
      // 登录成功存储token
      Tool.locals.setSession('token', res.data.token);
      Tool.locals.setSession('username', res.data.username);
      router.push('/');
    } else {
      dispath(getUsers());
    }
  });
// export default loginAction
